<?php
/**
 * Ajax接口通用控制器
 * User: crstu
 * Date: 2016/6/11
 * Time: 21:53
 */

namespace backend\controllers;

use yii;
use common\models\DAO\User;
use backend\commands\BaseAdminController;

class AjaxController extends BaseAdminController
{

    public function init()
    {
        parent::init();
        if(!Yii::$app->request->isAjax) return false;
    }

    /**
     * 根据用户ID返回用户名称
     * @param $id
     * @return string
     */
    public function actionGetUserInfo()
    {
        $request = Yii::$app->request;
        $userID  = floatval($request->get('userID'));
        $tradeID = floatval($request->get('tradeID'));
        if(!empty($userID) || !empty($tradeID)){
            $query = User::find()->select('id,tradeID,realName');
            if(!empty($id)) {
                $info = $query->andFilterWhere(['id' => $userID])->asArray()->one();
            }else{
                $info = $query->andFilterWhere(['tradeID' => $tradeID])->asArray()->one();
            }
            if(!empty($info)){
                return $this->renderJson(1, $info);
            }else{
                return $this->renderJson(0, '', '查无此人');
            }

        }
        return $this->renderJson(0, [], '系统推荐');
    }

    public function actionCheckUserPhone(){
        
    }

}